package online.longzipeng.mywebdemo.commen.exception;


import lombok.Data;

/**
 * 通用异常处理
 */
@Data
public class ServiceException extends RuntimeException {
	private static final long serialVersionUID = 1L;

	/**
	 * 错误码
	 */
	private int code;

	/**
	 * 错误信息
	 */
	private String msg;

	public ServiceException(int code) {
		this.code = code;
	}

	public ServiceException(int code, String msg) {
		this.code = code;
	}

	public ServiceException(String msg) {
		super(msg);
		this.code = ErrorCodeEnum.ERROR.value;
		this.msg = msg;
	}

	/**
	 * 使用通用错误枚举快速创建异常
	 */
	public ServiceException(ErrorCodeEnum errorCodeEnum) {
		this.code = errorCodeEnum.getValue();
		this.msg =errorCodeEnum.getTitle();
	}

}
